﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Admin.Common
{
    public class BaseController : Controller
    {
        public string lang
        {
            get
            {
                if (Request.QueryString["lang"]!=null)
                {
                   return Request.QueryString["lang"].ToString();
                }
                return "vn";
            }
        }

        protected void ChangLanguage()
        {
            if (!string.IsNullOrEmpty(lang))
            {
                switch (lang)
                {
                    case "vn":
                        SessionManager.CurrentCulture = 0;
                        Session["CurrentCulture"] = 0;
                        break;
                    case "en":
                        SessionManager.CurrentCulture = 1;
                        Session["CurrentCulture"] = 1;
                        break;
                    default:
                        SessionManager.CurrentCulture = 0;
                        Session["CurrentCulture"] = 0;
                        break;
                }
            }
        }

     

        protected override void ExecuteCore()
        {
            int culture = 0;
            if (this.Session == null || this.Session["CurrentCulture"] == null)
            {
                int.TryParse(System.Configuration.ConfigurationManager.AppSettings["Culture"], out culture);
                this.Session["CurrentCulture"] = culture;
            }
            else
            {
                culture = (int)this.Session["CurrentCulture"];
            }
            //
            SessionManager.CurrentCulture = culture;
            //
            // Invokes the action in the current controller context.
            //
            ChangLanguage();
            base.ExecuteCore();
        }

        protected override bool DisableAsyncSupport
        {
            get { return true; }
        }

        

   
    }
}
